package com.yoomiito.app.utils;

import android.text.TextUtils;
import android.view.View;

import com.umeng.analytics.MobclickAgent;
import com.yoomiito.app.base.App;

import java.util.HashMap;

/**
 * 友盟埋点
 */
public class TouchUtils {

    public static void startPageCollection(){
        MobclickAgent.setPageCollectionMode(MobclickAgent.PageMode.AUTO);
    }


    public static void OnPageStart(){
//        MobclickAgent.onPageStart();
    }

    public static void onPageEnd(){

    }

    public static void onEvent(String eventId) {
        if (TextUtils.isEmpty(eventId)) return;
        MobclickAgent.onEvent(App.getInstance(), eventId);
    }

    /**
     * 分享统计点击行为次数
     * @param eventId 事件ID
     * @param userLevel 用户级别
     * @param isAgent 区代
     * @param shareChannel 分享渠道
     */
    public static void onShareEvent(String eventId,int userLevel,int isAgent,String shareChannel){
        if (TextUtils.isEmpty(eventId))return;
        MobclickAgent.onEvent(App.getInstance(), eventId, getParams(userLevel, isAgent, shareChannel,""));
    }

    /**
     * 统计点击行为次数
     *
     * @param eventId
     * @param userLevel
     * @param isAgent
     */
    public static void onEvent(String eventId,int userLevel,int isAgent){
        if (TextUtils.isEmpty(eventId))return;
        MobclickAgent.onEvent(App.getInstance(), eventId, getParams(userLevel, isAgent, "",""));
    }

    /**
     * 购买支付统计
     * @param eventId
     * @param userLevel
     * @param isAgent
     * @param payState
     */
    public static void onBuyEvent(String eventId,int userLevel,int isAgent,String payState){
        if (TextUtils.isEmpty(eventId))return;
        MobclickAgent.onEvent(App.getInstance(), eventId, getParams(userLevel, isAgent, "",payState));
    }

    /**
     * 收藏统计
     * @param eventId
     * @param collection
     */
    public static void onCollectEvent(String eventId,int collection){
        if (TextUtils.isEmpty(eventId))return;
        HashMap<String,String> params = new HashMap<>();
        params.put("collectionState", String.valueOf(collection));
        MobclickAgent.onEvent(App.getInstance(), eventId, params);
    }

    private static HashMap<String,String> getParams(int userLevel,int isAgent,String shareChannel,String payState){
        HashMap<String,String> params = new HashMap<>();
        params.put("user_level",String.valueOf(userLevel));
        params.put("is_region_agent",String.valueOf(isAgent));
        if (!TextUtils.isEmpty(shareChannel))
            params.put("share_channel",shareChannel);
        if (!TextUtils.isEmpty(payState))
            params.put("pay_state",payState);
        return params;
    }


//    public static void onEvent(View view, String id, TouchClick clickListener) {
//        if (clickListener == null || TextUtils.isEmpty(id) || view == null)
//            throw new NullPointerException("params can`t null");
//        view.setOnClickListener(v -> {
//            onEvent(id);
//            clickListener.onClick(v);
//        });
//    }
//
//    public static <T> ClickTransformer<T> observableEvent(String touchId) {
//        if (TextUtils.isEmpty(touchId)) throw new NullPointerException("id can`t null");
//        return new ClickTransformer<>(touchId);
//    }
//
//    public static void recordHomeButtonTouch(int position) {
//        switch (position) {
//            case C.HomeInteraction.INVESTMENT_LIST:
//                TouchUtils.onEvent("invest");
//                break;
//            case C.HomeInteraction.USER_CENTER:
//                TouchUtils.onEvent("my");
//                break;
//        }
//    }
}
